package com.mp.approvalreq.util;

import com.mp.approvalreq.entity.Participant;
import com.mp.user.entity.User;
import com.plusmoney.util.Utils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class ParticipateUtils {

    public static boolean isExistUser(List<Participant> participants, User user) {
        return isExistUser(participants, user.getCompanyInfoId());
    }


    public static boolean isExistUser(List<Participant> participants, Integer companyInfoId) {
        if (Utils.isEmpty(participants)) {
            return false;
        }
        return participants.stream().anyMatch(participant -> Objects.equals(participant.getCompanyInfoId(), companyInfoId));
    }

    public static String getContactIds(List<Participant> participants) {
        if (Utils.isEmpty(participants)) {
            return null;
        }
        List<Integer> ids = participants.stream().map(Participant::getContactId).collect(Collectors.toList());
        return ListHelper.list2string(ids);
    }

    public static String getCompanyInfoIds(List<Participant> participants) {
        if (Utils.isEmpty(participants)) {
            return null;
        }
        List<Integer> ids = participants.stream().map(Participant::getCompanyInfoId).collect(Collectors.toList());
        return ListHelper.list2string(ids);
    }
}
